package cn.lizhangqu.kb.model;

import android.util.Log;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

import java.io.Serializable;

import cn.lizhangqu.kb.api.LgrgApi;

/**
 * Created by 柯尊诚 on 2015/11/6.
 * kzc
 */
public class Report implements Serializable {

    private String id;//编号
    private String createDate;//创建日期
    private String createTime;//创建时间
    private String updDate;//更新日期
    private String updTime;//更新时间
    private String releaseDate;//发布时间
    private String title; //标题
    private String content;//正文
    private String editorAuthor;//作者
    private String showSeat;//来自
    private String display;//状态
    private String image;//图片，可无

    public String getId() {
        return id;
    }

    public String getReleaseDate() {
        return releaseDate;
    }

    public void setReleaseDate(String releaseDate) {
        this.releaseDate = releaseDate;
    }

    public String getUpdDate() {
        return updDate;
    }

    public void setUpdDate(String updDate) {
        this.updDate = updDate;
    }

    public String getUpdTime() {
        return updTime;
    }

    public void setUpdTime(String updTime) {
        this.updTime = updTime;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getCreateDate() {
        return createDate;
    }

    public void setCreateDate(String createDate) {
        this.createDate = createDate;
    }

    public String getCreateTime() {
        return createTime;
    }

    public void setCreateTime(String createTime) {
        this.createTime = createTime;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = replaceString(title);
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        Document doc = Jsoup.parse(content);
        content = doc.text();

        this.content = content;
        Log.d("qqq!",content);
        Log.d("qqqq",content.indexOf("img")+"");
        if (content.indexOf("img") != -1) {
            int start = content.indexOf("src=\"") + 5;
            Log.d("qqqq", start + "");
            int end = content.indexOf("\"", start);
            if (end != -1) {
            Log.d("qqq", end + "");
                String data = content.substring(start, end);
                if (data.indexOf("gif") == -1) {
                    Log.d("qq", data);
                    if (getImage() == null || !getImage().isEmpty())
                        setImage(data);
                }
            }
        }
    }

    public String getEditorAuthor() {
        return editorAuthor;
    }

    public void setEditorAuthor(String editorAuthor) {
        this.editorAuthor = editorAuthor;
    }

    public String getShowSeat() {
        return showSeat;
    }

    public void setShowSeat(String showSeat) {
        this.showSeat = showSeat;
    }

    public String getDisplay() {
        return display;
    }

    public void setDisplay(String display) {
        this.display = display;
    }

    public String getImage() {
        return image;
    }


    public void setImage(String image) {
        if (image == null || image.isEmpty()) return;
        this.image = LgrgApi.BASE_URL + image;
    }

    @Override
    public String toString() {
        return "Report{" +
                "id='" + id + '\'' +
                ", createDate='" + createDate + '\'' +
                ", createTime='" + createTime + '\'' +
                ", updDate='" + updDate + '\'' +
                ", updTime='" + updTime + '\'' +
                ", releaseDate='" + releaseDate + '\'' +
                ", title='" + title + '\'' +
                ", image='" + image + '\'' +
                ", editorAuthor='" + editorAuthor + '\'' +
                ", showSeat='" + showSeat + '\'' +
                ", display='" + display + '\'' +
                ", content='" + content + '\'' +
                '}';
    }

    public String replaceString(String content) {
        if (content.indexOf("&ldquo;") != 0 || content.indexOf("&rdquo;") != 0) {
          content = content.replace("&rdquo;", "\"");
          content = content.replace("&ldquo;", "\"");
        }
        return content;
    }
}
